package guggaTests.collections.objectSet
{
	import flexunit.framework.TestCase;
	import flexunit.framework.Assert;

	import gugga.collections.objectSet.ObjectSet;

	public class ObjectSetTest extends TestCase
	{
		public function ObjectSetTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public function testAddContainsElement() : void
		{
			var objSet : ObjectSet = new ObjectSet();
			
			var obj1 : Object = { name: "first" };
			var obj2 : Object = { name: "second" };
			var obj3 : Object = { name: "second" };
			
			var stringObject1 : String = "Some text";
			var stringObject2 : String = "Some text";
			var stringObject3 : String = new String();
			stringObject3 = "Some text";
			var stringObject4 : String = new String(stringObject1);
			stringObject4 = "Some other text";
			

			var intObject1 : int = 3;
			var intObject2 : int = 3;
			var intObject3 : int = 4;

			
			
			objSet.addElement(obj1);
			objSet.addElement(obj2);
			
			obj1.name = "third";

			objSet.addElement(stringObject1);

			objSet.addElement(intObject1);
			
			assertTrue(
				"object set should contain obj1",
				objSet.containsElement(obj1)
			);
			
			assertTrue(
				"object set should contain obj2",
				objSet.containsElement(obj2)
			);
			
			assertFalse(
				"object set should not contain obj3",
				objSet.containsElement(obj3)
			);
			
			assertTrue(
				"object set should contain stringObject1",
				objSet.containsElement(stringObject1)	
			);
			
			assertTrue(
				"object set should contain stringObject2",
				objSet.containsElement(stringObject2)	
			);
			
			assertTrue(
				"object set should contain stringObject3",
				objSet.containsElement(stringObject3)	
			);
			
			assertFalse(
				"object set should not contain stringObject4",
				objSet.containsElement(stringObject4)	
			);
			
			assertTrue(
				"object set should contain intObject1",
				objSet.containsElement(intObject1)	
			);
			
			assertTrue(
				"object set should contain intObject2",
				objSet.containsElement(intObject2)	
			);
			
			assertFalse(
				"object set should not contain intObject3",
				objSet.containsElement(intObject3)	
			);
		}
		
		public function	testRemoveElement() : void
		{
			var testString : String = "TestString";
			var objSet : ObjectSet = new ObjectSet();
			
			objSet.addElement(testString);
			assertTrue(
				"The set should contain the test string obj",
				objSet.containsElement(testString)
				);
				
			objSet.removeElement(testString);
			
			assertFalse(
				"The set should not contain the test string obj",
				objSet.containsElement(testString)
				);
				
			objSet.removeElement(testString);
			
		}
		
		public function testGetAllElements () : void
		{
			var objSet : ObjectSet = new ObjectSet();
			
			var obj1 : Object = { name: "first" };
			var obj2 : Object = { name: "second" };
			var obj3 : Object = { name: "third" };
			
			var intObject1 : int = 3;
			var intObject2 : int = 3;
			var intObject3 : int = 5;
			
			objSet.addElement(obj2);
			objSet.addElement(obj1);
			
			objSet.addElement(intObject1)
			
			var setValues : Array = objSet.getAllElements();
						
			assertTrue(
				"obj1 must be in the array",
				(setValues.indexOf(obj1) > -1)
			);
			
			assertTrue(
				"obj3 must not be in the array",
				(setValues.indexOf(obj3) == -1)
			);
			
			assertTrue(
				"intObject2 must be in the array",
				(setValues.indexOf(intObject2) > -1)
			);
			
			assertTrue(
				"intObject3 must be in the array",
				(setValues.indexOf(intObject3) == -1)
			)
			
		}
	}
}